//
//  YsCloudFileUploadReamModel.m
//  YsCloudFileManageSDK
//
//  Created by 宋宏康 on 2020/2/26.
//

#import "YsCloudFileUploadReamModel.h"
#import "YsCloudFileRealmManager.h"
#import <YYKit/YYKit.h>

@implementation YsCloudFileUploadReamModel

+ (NSString *)primaryKey
{
    return @"uploadID";
}

- (int)incrementaID {
    NSArray *resultArray =  [[YsCloudFileRealmManager queryAllObj:YsCloudFileUploadReamModel.class] sortedArrayUsingComparator:^NSComparisonResult(YsCloudFileUploadReamModel *obj1, YsCloudFileUploadReamModel *obj2) {
        //此处的规则含义为：若前一元素比后一元素小，则返回降序（即后一元素在前，为从大到小排列）
        if (obj2.uploadID  < obj1.uploadID){
            return NSOrderedDescending;
        }else{
            return NSOrderedAscending;
        }
    }];
    
    if (resultArray.count != 0 || resultArray) { /// 如果有值
        YsCloudFileUploadReamModel *cloudFileUploadReamModel = resultArray.lastObject;
        return (int)(cloudFileUploadReamModel.uploadID + 1);
    }else {
        return 0;
    }
}


@end
